﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Zvezda.FSO2.DB;

namespace FSO.Reports
{
    /// <summary>
    /// Компонент для отображения параметров отчета "Полученные средства"
    /// </summary>
    public partial class UserControlVatInvoicesParams : UserControl, IReportParamList
    {
        public UserControlVatInvoicesParams()
        {
            InitializeComponent();
        }

        #region IReportParamList Members

        public Microsoft.Reporting.WinForms.ReportParameter[] Parameters
        {
            get 
            {
                List<ReportParameter> _listParams = new List<ReportParameter>(3);

                ReportParameter paramDateFrom = new ReportParameter("p_date_from", userControlDatePeriodSelector1.DateFrom.ToShortDateString(), false);
                _listParams.Add(paramDateFrom);

                ReportParameter paramDateTo = new ReportParameter("p_date_to", userControlDatePeriodSelector1.DateTo.ToShortDateString(), false);
                _listParams.Add(paramDateTo);

                string sNsiOrganization = null;
                string sNsiOrganizationName = null;
                if (!userControlOrganizationSelector1.IsNull)
                {
                    sNsiOrganization = userControlOrganizationSelector1.SelectedRow.ID.ToString();
                    sNsiOrganizationName = userControlOrganizationSelector1.SelectedRow.SHORT_NAME;
                }
                ReportParameter paramOrganization = new ReportParameter("p_nsi_organization_id", sNsiOrganization, false);
                _listParams.Add(paramOrganization);
                ReportParameter paramOrganizationName = new ReportParameter("v_organization", sNsiOrganizationName, false);
                _listParams.Add(paramOrganizationName);

                string sContractId = null;
                string sContractName = null;
                if (!userControlContractSelector1.IsNull)
                {
                    sContractId = userControlContractSelector1.SelectedRow.ID.ToString();
                    sContractName = userControlContractSelector1.SelectedRow.NUMBER;
                }
                _listParams.Add(new ReportParameter("p_contract_id", sContractId, false));
                _listParams.Add(new ReportParameter("v_contract_number", sContractName, false));

                string sTypeOfActivityValue = null;
                string sTypeOfActivityName = null;
                if (!userControlTypeOfActivitySelector1.IsNull)
                {
                    sTypeOfActivityValue = userControlTypeOfActivitySelector1.SelectedValue;
                    sTypeOfActivityName = userControlTypeOfActivitySelector1.SelectedText;
                }
                _listParams.Add(new ReportParameter("p_type_of_activity", sTypeOfActivityValue, false));
                _listParams.Add(new ReportParameter("v_nsi_type_of_activity", sTypeOfActivityName, false));

                string sVatInvTypeValue = null;
                if (radDropDownListType.SelectedValue != null)
                {
                    sVatInvTypeValue = radDropDownListType.SelectedValue.ToString();
                }
                string sVatInvTypeText = radDropDownListType.Text;
                _listParams.Add(new ReportParameter("p_vat_inv_type", sVatInvTypeValue, false));
                _listParams.Add(new ReportParameter("v_type", radDropDownListType.SelectedText, false));

                return _listParams.ToArray();
            }
        }

        #endregion

        /// <summary>
        /// Загружает данные из БД
        /// </summary>
        private void UserControlRecievedMeansParams_Load(object sender, EventArgs e)
        {
            radDropDownListType.Items.Clear();
            //Telerik.WinControls.UI.RadListDataItem nullSelect = new Telerik.WinControls.UI.RadListDataItem() { Text = "Все", Value = null };
            radDropDownListType.Items.Add(new Telerik.WinControls.UI.RadListDataItem() { Text = "Все", Value = null, Selected = true });
            radDropDownListType.Items.Add(new Telerik.WinControls.UI.RadListDataItem() { Text = "Товары", Value = 1 });
            radDropDownListType.Items.Add(new Telerik.WinControls.UI.RadListDataItem() { Text = "Работы", Value = 2 });
            radDropDownListType.Items.Add(new Telerik.WinControls.UI.RadListDataItem() { Text = "Услуги", Value = 3 });
            //radDropDownListType.SelectedItem = nullSelect;
        }
    }
}
